package com.x.Part2_单例模式;

/**
 * ClassName: Girlfriend
 * Package: IntelliJ IDEA
 * Description:单例模式 懒汉式
 * Written by HanXu
 * Create 2024.03.01 23:02
 */
public class GirlfriendTest {
    public static void main(String[] args) {

    }
}

class Girlfriend{
    //1、构造器私有化
    private Girlfriend(){

    }

    //2、声明实例
    private static Girlfriend instance = null;


    //3、通过get方法获得对象实例；如果没有创建，则在方法内部创建对象
    public static Girlfriend getInstance(){
        if(instance==null)
            instance = new Girlfriend();

        return instance;
    }


}
